import com.nekonomics.lakehouse.common.FlinkRunner._
import com.nekonomics.lakehouse.common.util.SqlUtil._
import com.nekonomics.lakehouse.common.adt.PaymentStatus._

/**
 * 商家订单汇总情况
 * 商家为粒度
 * 统计指标为订单数、销售金额、支付订单数、未支付订单数
 * 统计周期为天
 */



object MerchantOrderSummaryDailyAds {
  def main(args: Array[String]): Unit = {
    val tableName = "merchant_order_summary_daily_ads"

    implicit val config: SqlRunnerConfig = SqlRunnerConfig(groupId = tableName, port = 8087, ckp = true)

    runSql { (_, tableEnv) =>
      tableEnv.executeSql(
        sql"""
             |CREATE TEMPORARY TABLE $tableName (
             |  date_key DATE,
             |  merchant_id BIGINT,
             |  total_sales DECIMAL(10, 2),
             |  total_items INT,
             |  paid_orders INT,
             |  unpaid_orders INT,
             |  PRIMARY KEY (merchant_id, date_key) NOT ENFORCED
             |) WITH ${jdbcConnector(s"ads.$tableName")}
             |""".stripMargin
      )

      tableEnv.executeSql(
        sql"""
             |INSERT INTO $tableName
             |SELECT
             |  date_key,
             |  merchant_id,
             |  total_sales,
             |  total_items,
             |  paid_orders,
             |  unpaid_orders
             |FROM dws.order_merchant_summary_daily_dws
             |
             |""".stripMargin
      )


    }


  }


}
